package com.wangxiaoxuan.seckill.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.wangxiaoxuan.seckill.mapper.SeckillGoodsMapper;
import com.wangxiaoxuan.seckill.pojo.SeckillGoods;
import com.wangxiaoxuan.seckill.service.ISeckillGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangxiaoxuan
 * @since 2022-03-23
 */
@Service
public class SeckillGoodsServiceImpl extends ServiceImpl<SeckillGoodsMapper, SeckillGoods> implements ISeckillGoodsService {

    @Autowired
    private SeckillGoodsMapper seckillGoodsMapper;
    /**
     * 秒杀成功给库存减1
     * @param seckillGoods
     * @return
     */
    @Override
    public Boolean decreaseStock(SeckillGoods seckillGoods) {
       // System.out.println("--------------------------------------------------");
        UpdateWrapper<SeckillGoods> wrapper = new UpdateWrapper<>();
        wrapper.eq("goods_id",seckillGoods.getGoodsId()).gt("stock_count",0).set("stock_count",0);
        seckillGoodsMapper.update(seckillGoods, wrapper);
        return true;
    }
}
